﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Blade.IO;
using System.Collections;
using System.IO;

namespace Blade.Metadata.CliLoader.Metadata {
	sealed class CliTable<TRow> : IList<TRow>, ICliTable
		where TRow : CliRow, new() {

		TRow[] data;

		public CliTable(MetadataTable tableId, int rowCount, TableReader reader, IMetadataLoaderContext context) {
			this.Count = rowCount;
			data = new TRow[rowCount];
			for (int i = 0; i < reader.RowCount; i++) {
				data[i] = new TRow();
				data[i].Read(reader, context);
			}
		}

		public MetadataTable TableId { get; private set; }

		Type ICliTable.RowType { get { return typeof(TRow); } }

		public int Count { get; private set; }

		#region IList<TRow> Members

		void IList<TRow>.Insert(int index, TRow item) {
			throw new NotImplementedException();
		}

		void IList<TRow>.RemoveAt(int index) {
			throw new NotImplementedException();
		}

		#endregion

		#region ICollection<TRow> Members

		void ICollection<TRow>.Add(TRow item) {
			throw new NotSupportedException();
		}

		void ICollection<TRow>.Clear() {
			throw new NotImplementedException();
		}

		bool ICollection<TRow>.IsReadOnly { get { return true; } }

		bool ICollection<TRow>.Remove(TRow item) {
			throw new NotSupportedException();
		}

		#endregion

		#region IList<TRow> Members

		public int IndexOf(TRow item) {
			return Array.IndexOf(data, item);
		}


		#endregion

		#region ICollection<TRow> Members


		public bool Contains(TRow item) {
			throw new NotImplementedException();
		}

		public void CopyTo(TRow[] array, int arrayIndex) {
			throw new NotImplementedException();
		}

		#endregion

		#region IEnumerable<TRow> Members

		public IEnumerator<TRow> GetEnumerator() {
			throw new NotImplementedException();
		}

		#endregion

		#region IEnumerable Members

		IEnumerator IEnumerable.GetEnumerator() {
			throw new NotImplementedException();
		}

		#endregion

		public TRow this[int index] {
			get { return data[index]; }
			set { throw new NotSupportedException(); }
		}
	}
}
